package com.alibaba.sample.kantiezi.web.admin.module.screen;

import com.alibaba.biz.command.Command;
import com.alibaba.biz.command.CommandSupport;
import com.alibaba.biz.command.dispatcher.CommandDispatcher;
import com.alibaba.biz.command.result.Result;

import com.alibaba.sample.kantiezi.dal.dataobject.Category;

import com.alibaba.service.template.TemplateContext;

import com.alibaba.turbine.module.screen.TemplateScreen;
import com.alibaba.turbine.service.rundata.RunData;

import com.alibaba.webx.WebxException;

public abstract class AddProduct extends TemplateScreen {
    protected abstract CommandDispatcher getCommandDispatcher();

    protected void execute(RunData rundata, TemplateContext context)
            throws WebxException {
        String  categoryId = rundata.getParameters().getString("categoryId");
        Command command    = new CommandSupport("addProduct", "getCategory");

        command.getParameters().put("categoryId", categoryId);

        Result result = getCommandDispatcher().execute(command);

        if (result.isSuccess()) {
            Category category = (Category) result.getDefaultModel();

            context.put("category", category);
        }
    }
}
